package com.jn.algorithm.day023.question73;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author 江南大学1033190417
 * @date 2022/5/14 10:44
 */
public class Solution {
    public void setZeroes(int[][] matrix) {
        Set<Integer> row = new HashSet<>();
        Set<Integer> column = new HashSet<>();
        int m = matrix.length;
        int n = matrix[0].length;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (matrix[i][j] == 0) {
                    row.add(i);
                    column.add(j);
                }
            }
        }
        for (Integer num : row) {
            for (int i = 0; i < n; i++) {
                matrix[num][i] = 0;
            }
        }
        for (Integer num : column) {
            for (int i = 0; i < m; i++) {
                matrix[i][num] = 0;
            }
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[][] matrix = new int[][]{
                {0, 1, 2, 0},
                {3, 4, 5, 2},
                {1, 3, 1, 5}
        };
        solution.setZeroes(matrix);
        for (int i = 0; i < matrix.length; i++) {
            System.out.println(Arrays.toString(matrix[i]));
        }
    }
}